package algorithm;

/**
 * 字符串匹配暴力破解
 */
public class ViolenceMactch {
  public static void main(String[] args) {
    //
      String s1="2345799456335";
      String s2="4563";
      int index = violenceMactch(s1, s2);
    System.out.println(index);
  }


  public static int violenceMactch(String s1,String s2){
      int i=0;
      int j=0;
      int s1Length = s1.length();
      int s2Length = s2.length();
      char[] char1 = s1.toCharArray();
      char[] char2 = s2.toCharArray();

      while (i<s1.length()&&j<s2Length){
           if (char1[i]==char2[j]){
               i++;
               j++;
           }else {
               i= i-j+1;
               j=0;
           }
      }
      if (j==s2Length){
          return i-j;
      }else {
          return -1;
      }
  }
}
